package jayesh.gps;



import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class listATMAddress extends Activity {
private ListView list2;

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.atm_add_list);
    list2 =(ListView)findViewById(R.id.list2);
    add_list();
  
}

public void add_list(){
	SQLiteDatabase myDB = this.openOrCreateDatabase(DefaultDBHelper.DATABASE_NAME, SQLiteDatabase.OPEN_READWRITE, null);
	final ArrayList<String> results = new ArrayList<String>();
	try {
        
        
         /* Create the Database (no Errors if it already exists) */
                    // myDB = dbHelper.getWritableDatabase();
                    // dbHelper.onCreate(myDB);
          /*   myDB.execSQL("CREATE TABLE IF NOT EXISTS " 
	                          + DefaultDBHelper.ATMTABLE
	                          + " ("+DefaultDBHelper.KEY_ATM_ID +"integer primary key autoincrement," +
	                          		DefaultDBHelper.KEY_BANK_NAME+" VARCHAR," +
	                          		DefaultDBHelper.KEY_ATM_ADD+" VARCHAR," +
	                          		DefaultDBHelper.KEY_CITY+" VARCHAR" +
	                          		DefaultDBHelper.KEY_LONGI+" REAL," +
	                          		DefaultDBHelper.KEY_LATI+"REAL);");*/
                            // -- openOrCreateDatabase(name, mode, factory)
                    // myDB = dbHelper.getReadableDatabase();
     
     String[] columns={DefaultDBHelper.KEY_BANK_NAME,DefaultDBHelper.KEY_ATM_ADD};
     Cursor c = myDB.query("atmtable2",columns,null, null, null, null,null);
     startManagingCursor(c);
     int col  =c.getCount();
     /* Check if our result was valid. */ 
 if (c != null) {
 
     c.moveToFirst(); // it's very important to do this action otherwise your Cursor object did not get work
     
     int bankNameColumn = c.getColumnIndex(DefaultDBHelper.KEY_BANK_NAME); 
     int AtmAddColumn = c.getColumnIndex(DefaultDBHelper.KEY_ATM_ADD);
      /* Check if at least one Result was returned. */ 
      if (c.isFirst()) { 
           int i = 0;

           /* Loop through all Results */ 
           do { 
                i++; 
                String bankName = c.getString(bankNameColumn); 
                String atmAdd = c.getString(AtmAddColumn);
               
               c.moveToNext();
               results.add("\t" + bankName + "\t|  " +atmAdd);
           } while (i!=col); 
      } 
      list2.setAdapter(new ArrayAdapter<String>(this, R.layout.front_list, results));
    
      
      
 }    
    } catch (SQLiteException e) { 
  	  System.out.println(e);
    } finally { 
         if (myDB != null) 
              myDB.close(); 
    }
 }

}